home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / Calc / CalcUtilities.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  3.7 KB  |  146 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. { CalcUtilities.inc1.p}
  3. { Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.}
  4.  
  5. {--------------------------------------------------------------------------------------------------}
  6. {$S ARes}
  7.  
  8. PROCEDURE FitString(VAR theString: Str255;
  9.                     maxWidth: INTEGER);
  10. { Truncates theString to fit in maxWidth pixels }
  11.  
  12.     VAR
  13.         currWidth:            INTEGER;
  14.         noOfChars:            INTEGER;
  15.  
  16.     BEGIN
  17.     IF StringWidth(theString) > maxWidth THEN
  18.         BEGIN
  19.         currWidth := CharWidth('…');
  20.         noOfChars := 0;
  21.         REPEAT
  22.             noOfChars := noOfChars + 1;
  23.             currWidth := currWidth + CharWidth(theString[noOfChars]);
  24.         UNTIL currWidth > maxWidth;
  25.  
  26.         {$Push} {$R-}
  27.         theString[0] := CHR(noOfChars);                 { Set length of theString }
  28.         {$Pop}
  29.         theString[noOfChars] := '…';
  30.         END;
  31.     END;
  32.  
  33. {--------------------------------------------------------------------------------------------------}
  34. {$S ARes}
  35.  
  36. FUNCTION IsDigit(Ch: CHAR): BOOLEAN;
  37.  
  38.     BEGIN
  39.     IsDigit := (Ch >= '0') AND (Ch <= '9');
  40.     END;
  41.  
  42. {--------------------------------------------------------------------------------------------------}
  43. {$S ARes}
  44.  
  45. PROCEDURE SetEditCmdName(theCommand, customCommand: INTEGER);
  46. { Sets the Edit menu command name to the custom name, e.g. 'Copy Cells'. }
  47.  
  48.     VAR
  49.         commandName:        Str255;
  50.  
  51.     BEGIN
  52.     CmdToName(customCommand, commandName);
  53.     SetCmdName(theCommand, commandName);
  54.     END;
  55.  
  56. {--------------------------------------------------------------------------------------------------}
  57. {$S ARes}
  58.  
  59. PROCEDURE SetTheFont(fontNumber, fontSize: INTEGER;
  60.                      fontStyle: Style);
  61.  
  62.     BEGIN
  63.     TextFont(fontNumber);
  64.     TextSize(fontSize);
  65.     TextFace(fontStyle);
  66.     END;
  67.  
  68. {--------------------------------------------------------------------------------------------------}
  69. {$S ARes}
  70.  
  71. PROCEDURE SmartDrawString(theString: Str255;
  72.                           area: Rect;
  73.                           justification: INTEGER);
  74.  { Draws the string at the [h,v] coordinate, taking into account the
  75.   width and justification. }
  76.  
  77.     BEGIN
  78.     WITH area DO
  79.         FitString(theString, right - left);
  80.     MADrawString(@theString, area, justification);
  81.     END;
  82.  
  83. {--------------------------------------------------------------------------------------------------}
  84. {$S AReadFile}
  85.  
  86. PROCEDURE ReadBytes(theRefNum: INTEGER;
  87.                     size: LONGINT;
  88.                     buffer: Ptr);
  89. { Utility for reading data from a file }
  90.  
  91.     BEGIN
  92.     FailOSErr(FSRead(theRefNum, size, buffer));
  93.     END;
  94.  
  95. {--------------------------------------------------------------------------------------------------}
  96. {$S AWriteFile}
  97.  
  98. PROCEDURE WriteBytes(theRefNum: INTEGER;
  99.                      size: LONGINT;
  100.                      buffer: Ptr);
  101. { Utility for writing data to a file }
  102.  
  103.     BEGIN
  104.     FailOSErr(FSWrite(theRefNum, size, buffer));
  105.     END;
  106.  
  107. {--------------------------------------------------------------------------------------------------}
  108. {$S AClipBoard}
  109.  
  110. PROCEDURE ReadScrap(theScrap: Handle;
  111.                     VAR scrapOffset: LONGINT;
  112.                     theData: Ptr;
  113.                     dataLength: INTEGER);
  114.  { Utility for extracting data from the scrap, where scrapOffset indicates
  115.   the start of the data within the scrap handle, and dataLength is the length of
  116.   the data to be extracted.  dataLength is added to scrapOffset. }
  117.  
  118.     VAR
  119.         p:                    Ptr;
  120.  
  121.     BEGIN
  122.     p := POINTER(ORD4(theScrap^) + scrapOffset);
  123.     BlockMove(p, theData, dataLength);
  124.     scrapOffset := scrapOffset + dataLength;
  125.     END;
  126.  
  127. {--------------------------------------------------------------------------------------------------}
  128. {$S AClipBoard}
  129.  
  130. PROCEDURE WriteScrap(theScrap: Handle;
  131.                      VAR scrapOffset: LONGINT;
  132.                      theData: Ptr;
  133.                      dataLength: INTEGER);
  134. { Utility for appending data to the end of the scrap handle }
  135.  
  136.     VAR
  137.         p:                    Ptr;
  138.  
  139.     BEGIN
  140.     SetHandleSize(theScrap, scrapOffset + dataLength);
  141.     FailMemError;
  142.     p := POINTER(ORD4(theScrap^) + scrapOffset);
  143.     BlockMove(theData, p, dataLength);
  144.     scrapOffset := scrapOffset + dataLength;
  145.     END;
  146.